package Test;

import Test.Bean.MyServerCusConfigBean;
import Test.Bean.MySqlCusConfigBean;
import Test.Bean.RedisCusConfigBean;
import Test.Bean.ThirdBean;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication(scanBasePackages = "Test")
public class MyFirst {

    public static void main(String[] args){

        // 返回IOC容器
        ApplicationContext appContext = SpringApplication.run(MyFirst.class, args);

        /**
         * 返回IOC组件名称
         * 加载了需要使用的web各种组件，包括中文乱码，文件上传，校验，
         * 默认包解析为主文件所在目录以及子目录，即MyFirst.class所在的Test文件夹以及子目录
         * @SpringBootApplication(scanBasePackages = "xx")扩大包扫描范围，或者使用@SpringBootApplication内的@ComponentScan
         *
          */
        String[] namesArr = appContext.getBeanDefinitionNames();
        int i = 1;
        for (String name : namesArr) {
            System.out.println(i + "--" + name);
            i++;
        }

        // 默认的环境配置
        System.out.println(appContext.getEnvironment().toString());

        // 获取组件
        Object myConf = appContext.getBean("myConfig");
        System.out.println(myConf);
        MySqlCusConfigBean mySqlConf1 = appContext.getBean(MySqlCusConfigBean.class);
        System.out.println(mySqlConf1);
        MyServerCusConfigBean myServerConf =appContext.getBean(MyServerCusConfigBean.class);
        System.out.println(myServerConf);
        System.out.println("____________________");
        System.out.println(appContext.getBean(ThirdBean.class));
        System.out.println(appContext.getBean(RedisCusConfigBean.class));
        System.out.println("____________________");
        Object bean = appContext.getBean("org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory");
        System.out.println(bean);

    }
}